package com.example.base.util.validator;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.base.entity.Course;
import com.example.base.util.Response;

import java.util.ArrayList;
import java.util.List;

public class CourseCtrlValidate {

    public static void addCourseValidate(Course course, Response response) {
        response.setMsg("课程信息添加失败");
        response.setStatus(400);
        response.setData(0);

        List<String> params = new ArrayList<>();

        if (ObjectUtils.isEmpty(course.getCourseImagesId()))
            params.add("courseImagesId");

        if (ObjectUtils.isEmpty(course.getCourseProducer()))
            params.add("courseProducer");

        if (ObjectUtils.isEmpty(course.getCourseName()))
            params.add("courseName");

        if (ObjectUtils.isEmpty(course.getCreateName()))
            params.add("createName");

        if (ObjectUtils.isEmpty(course.getDelSign()))
            params.add("delSign");

        if (ObjectUtils.isEmpty(course.getIsHot()))
            params.add("isHot");

        if (ObjectUtils.isEmpty(course.getIsOpen()))
            params.add("isOpen");

        if (ObjectUtils.isEmpty(course.getIsRecommend()))
            params.add("isRecommend");

        if (ObjectUtils.isEmpty(course.getIsSold()))
            params.add("isSold");

        if (ObjectUtils.isEmpty(course.getLessonNum()))
            params.add("lessonNum");

        if (ObjectUtils.isEmpty(course.getCourseDuration()))
            params.add("courseDuration");

        if (ObjectUtils.isEmpty(course.getProfession()))
            params.add("profession");

        if (ObjectUtils.isEmpty(course.getSkillId()))
            params.add("skillId");

        if (ObjectUtils.isEmpty(course.getTeacherId()))
            params.add("teacherId");

        if (ObjectUtils.isEmpty(course.getTypeId()))
            params.add("typeId");


        if (params.size() >= 1) {
            String formatParams = String.join(",", params);
            response.setError("Required String parameter '" + formatParams + "' is not present");
        } else {
            response.setMsg("课程信息添加成功");
            response.setStatus(200);
        }
    }

    public static void updateCourseValidate(Course course, Response response) {
        response.setMsg("课程信息修改失败");
        response.setStatus(400);
        response.setData(0);

        List<String> params = new ArrayList<>();
        if (ObjectUtils.isEmpty(course.getCourseId()))
            params.add("courseId");

        if (ObjectUtils.isEmpty(course.getCourseImagesId()))
            params.add("courseImagesId");

        if (ObjectUtils.isEmpty(course.getCourseProducer()))
            params.add("courseProducer");

        if (ObjectUtils.isEmpty(course.getCourseName()))
            params.add("courseName");

        if (ObjectUtils.isEmpty(course.getUpdateName()))
            params.add("updateName");

        if (ObjectUtils.isEmpty(course.getDelSign()))
            params.add("delSign");

        if (ObjectUtils.isEmpty(course.getIsHot()))
            params.add("isHot");

        if (ObjectUtils.isEmpty(course.getIsOpen()))
            params.add("isOpen");

        if (ObjectUtils.isEmpty(course.getIsRecommend()))
            params.add("isRecommend");

        if (ObjectUtils.isEmpty(course.getIsSold()))
            params.add("isSold");

        if (ObjectUtils.isEmpty(course.getLessonNum()))
            params.add("lessonNum");

        if (ObjectUtils.isEmpty(course.getCourseDuration()))
            params.add("courseDuration");

        if (ObjectUtils.isEmpty(course.getProfession()))
            params.add("profession");

        if (ObjectUtils.isEmpty(course.getSkillId()))
            params.add("skillId");

        if (ObjectUtils.isEmpty(course.getTeacherId()))
            params.add("teacherId");

        if (ObjectUtils.isEmpty(course.getTypeId()))
            params.add("typeId");


        if (params.size() >= 1) {
            String formatParams = String.join(",", params);
            response.setError("Required String parameter '" + formatParams + "' is not present");
        } else {
            response.setMsg("课程信息修改成功");
            response.setStatus(200);
        }
    }
}